﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.EShop.Common.Entity;
using Runda.EShop.Bll;

namespace Runda.EShop.SaaS.BasManage
{
    public partial class ProductAdd : BasePage
    {
        public Guid ProductID
        {
            get
            {
                if (!string.IsNullOrEmpty(Request.QueryString["ProductID"]))
                {
                    return new Guid(Request.QueryString["ProductID"]);
                }
                else
                    return Guid.Empty;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            txtRegCertificateDate.Attributes.Add("onclick", "WdatePicker();");

            ddlTrademark.DataSource = new BasProductBll().QueryProductTrademark();
            ddlTrademark.DataTextField = "Trademark";
            ddlTrademark.DataValueField = "Trademark";
            ddlTrademark.DataBind();

            ddlCateType.DataSource = new BasProductBll().QueryProductCate();
            ddlCateType.DataTextField = "CateName";
            ddlCateType.DataValueField = "CateCode";
            ddlCateType.DataBind();

            ddlCateTypeEx.DataSource = new BasProductBll().QueryProductCateEx();
            ddlCateTypeEx.DataTextField = "CateName";
            ddlCateTypeEx.DataValueField = "CateCode";
            ddlCateTypeEx.DataBind();
            
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            BasProductEntity entity = null;
            MasterDataBll bll = new MasterDataBll();

            entity = new BasProductEntity();
            entity.ProductCode = ltlProductCode.Text;
            entity.ProductName = ltlProductName.Text;
            entity.Alias = txtAlias.Text;
            entity.Standard = ltlStandard.Text;
            entity.Unit = ltlOther.Text;
            entity.Trademark = ddlTrademark.SelectedValue;
            entity.CateCode = ddlCateType.SelectedValue;
            entity.CateCodeEx = ddlCateTypeEx.SelectedValue;
            entity.Company = rbCompany.SelectedValue;
            entity.ProductType = 2;

            DateTime dt = DateTime.Now;

            if (DateTime.TryParse(txtRegCertificateDate.Text, out dt))
            {
                entity.RegCertificateDate = dt;
            }

            bll.Insert(entity);
           
            ClientScript.RegisterStartupScript(this.GetType(), "success", "alert('保存成功.');parent.$.ligerDialog.hide();", true);
        }

    }
}